<?php
function getSignedRequestString($method, $apikey, $sigalg, $sigkey) {
	$ts = gmdate('YmdHis', time() + date('Z')); // Calculate UTC time
	$nonce = '';
	for ($i = 0; $i < 8; $i++) {
		$nonce .= sprintf("%02s", dechex(mt_rand(0, 255))); 
	}
	$to_be_signed_data = "{$method}?apikey={$apikey}&ts={$ts}&nonce={$nonce}";
	$signature = hash_hmac('sha1', $to_be_signed_data, $sigkey);
	return "{$to_be_signed_data}&sigalg={$sigalg}&sig={$signature}";
}

/*
 * Following two ~Key variables you should put into are generated by Enzyme
 * API Center. You can always check these values on your API Key Info page.
 * When you visit to check the values, do not mistake the term 'Signature'
 * and 'Signature Key'. Signature itself can be taken as the result(or goal)
 * of the signing action you are going to invoke. Enzyme API Center provides
 * only the Signature Key value for signing API request, which must be
 * preserved undisclosed in safe place.

 $SIG_KEY = "Signature Key";
 $API_KEY = "API Key";

 $baseUrl = "http://member.thinkfree.com/enzyme/api/";
 $method = "view"; // specify method type: view, convert, embed, etc.
 $baseSection = getSignedRequestString($method, $API_KEY, 'hmacsha1', $SIG_KEY);
 $paramSection = "&repotype=yourservice&repokey=/doc/path.doc&doctype=doc&checksum=1234&callback=handler";
 $url = $baseUrl . $baseSection . $paramSection;
 // Now request this $url, and you will get what you want!
 */
?>
